<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Help Desk
 * @version 	1.0
 * @author 		Kurosaki <kurosaki@zprofess.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

include_once(dirname(__FILE__)."/classes/ZratingObject.php");
require_once(_PS_MODULE_DIR_.'zhelpdesk/lib/zprofess/ZhelpdeskadminTab.php');
class ZadminRating extends ZhelpdeskadminTab
{

	public function __construct()
	{
		global $cookie;
		
		$this->table = 'zhelpdesk_ticket_rating';
	 	$this->className = 'ZratingObject';
	 	$this->lang = true;
	 	$this->edit = true;
		$this->delete = true;
		
		$this->fieldsDisplay = array(
		'id_zhelpdesk_ticket_rating' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 30),
		'rating' => array('title' => $this->l('Name'), 'width' => 100),
		'description' => array('title' => $this->l('Description'), 'width' => 500, 'maxlength' => 90, 'orderby' => false),
		'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'position', 'align' => 'center', 'position' => 'position'),
		'active' => array('title' => $this->l('Displayed'), 'active' => 'status', 'align' => 'center', 'type' => 'bool', 'orderby' => false));
		
		$this->identifier = 'id_zhelpdesk_ticket_rating';
        $this->identifiersDnd = array('id_zhelpdesk_ticket_rating' => 'id_zhelpdesk_ticket_rating');
        $this->_defaultOrderBy = 'position';
		
		parent::__construct();
	}


	/**
	 * add js position
	 */	
	public function display($token = NULL) {
		parent::display();
		// add js when change position
		echo ' 
			<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
			<script type="text/javascript">
				var token = \''.($token!=NULL ? $token : $this->token).'\';
				var come_from = \''.$this->table.'\';
				var alternate = \''.($this->_orderWay == 'DESC' ? '1' : '0' ).'\';
			</script>
			<script type="text/javascript" src="../modules/zhelpdesk/js/backoffice/backoffice-pnd.js"></script>
			';
	}
	
	public function displayForm($token = NULL)
	{
		global $currentIndex, $cookie;
		parent::displayForm();
		
		if (!($obj = $this->loadObject(true)))
			return;
		
		$langtags = 'rating¤description';
		echo '<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" enctype="multipart/form-data">
			'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" /> ' : '');
		echo '
			<fieldset style="width:900px;">
				<legend>'.$this->l('Status').'</legend>';
				
				echo $this->addElement('text',array (
										'label' => 'Name',
										'name' => 'rating',
										'langtags' => $langtags,
										'width' => 200,
										'note' => '',
										'more' => ''
				),true);
				echo $this->addElement('area',array (
									'label' => 'Description',
									'name' => 'description',
									'langtags' => $langtags,
									'width' => 200,
									'note' => '',
									'more' => ''
				),true);
				echo '<br/><label>Value</label>';
				echo '<div class="margin-form">
						<input type="text" value="'.$obj->value.'" class="text" id="value" name="value" style="width:200px"> <sup>*</sup>
						<p class="clear"></p>
					</div>';
				
				echo $this->addElement('yesno',array (
						'label' => 'Active',
						'name' => 'active',
						'width' => 200,
						'value' => $obj->active,
						'note' => '',
						'more' => ''
				),true);
		
		echo '
			<div class="margin-form">
					<input type="submit" value="'.$this->l('Save').'" name="submitAdd'.$this->table.'AndBackToParent" class="button" />
				</div>
				<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
			</fieldset>
		</form>';
	}
	
}
